<template>
  <div class="app-body" v-loading="formitemLoading">
    <!------------- 编辑: 个人经历页面 ------------->
    <template v-if="componentStatus && componentStatus.personalExperience">
      <!-- 工作经历table -->
      <div class="from-item-title mb15">
        <span class="title">工作经历</span>
        <el-link :underline="false" icon="el-icon-plus" @click="editWorks('work')">添加经历</el-link>
      </div>
      <div>
        <tableBox
          :id="id"
          :table-data="workData"
          :table-label="workLabel"
          :type="edit"
          style="margin-bottom: 20px"
          table-name="works"
        ></tableBox>
      </div>

      <!-- 教育经历table -->
      <div class="from-item-title mb15">
        <span class="title">教育经历</span>
        <el-link :underline="false" icon="el-icon-plus" @click="editEducation('education')">添加经历</el-link>
      </div>
      <div>
        <tableBox
          :id="id"
          :table-data="educationsData"
          :table-label="educationLabel"
          :type="edit"
          style="margin-bottom: 20px"
          table-name="education"
        ></tableBox>
      </div>
    </template>

    <!-------------- 新增:新增页面 ------------>
    <el-form v-else ref="form" :model="ruleForm" :rules="fromRules" label-width="110px">
      <div v-for="(formItem, itemIndex) in newFrom" :key="itemIndex" class="p20">
        <div
          v-if="componentStatus.type === 'add' || !['工作经历', '教育经历'].includes(formItem.title)"
          :id="itemIndex"
          :class="FORMITEMISEDIT[itemIndex] && componentStatus.type === 'edit' ? 'm10' : 'mb15'"
          class="from-item-title"
        >
          <!-- 表单头标题 -->
          <span class="title">
            {{ formItem.title }}
            <!-- 个人简历需要展示的文字 -->
            <span v-if="formItem.title === '银行卡信息' && user === '个人简历'" class="text-title">
              <i class="el-icon-warning"></i>
              银行卡信息为敏感信息，右侧简历不会发送给其他企业</span
            >
            <span v-if="formItem.title === '社保信息' && user === '个人简历'" class="text-title">
              <i class="el-icon-warning"></i>
              社保信息为敏感信息，右侧简历不会发送给其他企业</span
            >
            <span v-if="formItem.title === '个人材料' && user === '个人简历'" class="text-title">
              <i class="el-icon-warning"></i>
              个人材料为敏感信息，右侧简历不会发送给其他企业
            </span>
          </span>

          <!-- 修改按钮 -->
          <span v-if="FORMITEMISEDIT[itemIndex] && componentStatus.type === 'edit'" class="editBtn">
            <el-link
              :underline="false"
              icon="el-icon-edit-outline"
              @click="FORMITEMISEDIT[itemIndex] = !FORMITEMISEDIT[itemIndex]"
              >编辑</el-link
            >
          </span>
          <div v-if="!FORMITEMISEDIT[itemIndex]">
            <el-button size="small" @click="restFn(itemIndex)">取消</el-button>
            <el-button size="small" type="primary" @click="formItemEdit(formItem.edit_type, itemIndex)">确定</el-button>
          </div>

          <!-- 新增:添加经历 -->
          <span v-if="['工作经历', '教育经历'].includes(formItem.title)">
            <div style="padding: 10px">
              <el-link :underline="false" icon="el-icon-plus" @click="addWorks(formItem.title)">添加经历</el-link>
            </div>
          </span>
        </div>

        <!-- 工作经历table -->
        <tableBox
          v-if="formItem.slot === 'workExperience' && componentStatus.type === 'add'"
          :person-id="personId"
          :table-data="workData"
          :table-label="workLabel"
          :type="(edit = 'add')"
          :user="user"
          style="margin-bottom: 20px"
          table-name="works"
          @deleteWork="deleteWork"
          @putWork="putWork"
        ></tableBox>

        <!-- 教育经历table -->
        <tableBox
          v-if="formItem.slot === 'educationalExperience' && componentStatus.type === 'add'"
          :person-id="personId"
          :table-data="educationsData"
          :table-label="educationLabel"
          :type="(edit = 'add')"
          :user="user"
          style="margin-bottom: 20px"
          table-name="education"
          @deleteWork="deleteWork"
          @putWork="putWork"
        ></tableBox>

        <!-- 表单数据内容 -->
        <div class="form-box">
          <div v-for="(item, index) in formItem.data" :key="index" class="form-item">
            <el-form-item
              :class="
                FORMITEMISEDIT[itemIndex] && componentStatus.type === 'edit' && item.type !== 'uploadImg'
                  ? 'activeItem'
                  : ''
              "
              :prop="item.value"
            >
              <!-- 表单label -->

              <span
                slot="label"
                :class="FORMITEMISEDIT[itemIndex] && componentStatus.type === 'edit' ? 'label' : 'labelfont'"
                >{{ item.label }}</span
              >

              <!-- 编辑状态用span来替换input来显示-->
              <div
                v-if="FORMITEMISEDIT[itemIndex] && componentStatus.type === 'edit' && item.type !== 'uploadImg'"
                class="label-item"
              >
                <span
                  v-if="
                    !['cascader', 'frame_id', 'manage_frame'].includes(item.slot) &&
                    !['radio', 'select'].includes(item.type)
                  "
                  >
                      <!-- dengshunbo 2024-12-24改 -->
                      <span v-if="item.type != 'switchspan' && item.type != 'selectoptions' && item.type != 'carinput' && item.type != 'file'">
                        {{ ruleForm[item.value] }}
                      </span>
                      <!-- end -->
                      <!-- {{ ruleForm[item.value] }}  原代码-->
                  </span
                >
                <div v-if="item.slot === 'frames'">
                  <span v-for="(item, index) in rangeUserText" :key="index">{{ item }} </span>
                </div>

                <span v-if="item.slot === 'cascader'">{{ positionText }}</span>
                <span v-if="item.slot === 'manage_frame'">{{ manage_frameText }}</span>
                <span v-if="item.value === 'is_part'">{{ is_partText }}</span>
                <span v-if="item.value === 'type'">{{ typeText }}</span>
                <span v-if="item.value === 'sex'">{{ sexText }}</span>
                <span v-if="item.value === 'marriage'">{{ marriageText }}</span>
                <span v-if="item.value === 'education'">{{ educationText }}</span>
                <div v-if="item.type === 'radio'">
                  {{ is_adminText }}
                </div>
                <template v-if="item.slot === 'superior_uid' && is_adminText === '是'">
                  <span>{{ superiorText }}</span>
                </template>

                <div v-if="item.slot === 'frame_id'">
                  <span v-for="(item, index) in frameText" :key="index" class="mr5"
                    >{{ item.name }} <span v-if="item.is_mastart" style="color: #1890ff; font-size: 13px"> (主) </span>
                  </span>
                </div>
                <!-- dengshunbo 2024-12-21 -->
                <div v-if="componentStatus.type !='add'">
                    <el-switch  v-if="item.type === 'switchspan'"
                        v-model="switchValue" :width="swidthwidth"
                        active-color="#999999"
                        inactive-color="#1890ff"
                        active-text="未下发"
                        inactive-text="已下发"
                        :disabled="true"
                        >
                    </el-switch>
                    <div v-if="item.type === 'selectoption'">
                      <div>
                          <div style="display:inline-block;width:180px;"  class="menjiselectinput">
                            <el-select v-model="authend_group_sn" filterable multiple collapse-tags placeholder="搜索或选择门禁组(多选)" @change="goMenjinzuChange" size="small">
                              <el-option
                                v-for="item in menjinData"
                                :key="item.value"
                                :label="item.menjinzumingcheng"
                                :value="item.id">
                              </el-option>
                            </el-select>
                          </div>
                          <div style="width:140px;display:inline-block">
                            <el-date-picker style="width:100%;"
                                v-model="authend_time"  size="small"
                                type="date" 
                                placeholder="授权结束日期"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd" 
                                >
                            </el-date-picker>
                          </div>
                      </div>
                    </div>
                    <div v-if="item.type === 'selectoptions'" >
                        <span v-if="item.value === 'yaoqingmenjinzu'">{{ getFileterData(authend_group_primess) }}</span>
                    </div>
                    
                </div>
                <div  v-if="item.type === 'carinput'">
                      {{ ruleForm[item.value] }}
                    <span v-if="ruleForm[item.value]">
                      <span v-if="!ruleForm.cheliangdisanfangpingtaiID" type="text" size="mini" @click.stop="goCarxiafa()" style="color:#1890ff;border:1px solid #1890ff;font-size:12px;
                      display:inline-block;padding:0px 4px;border-radius:2px;cursor: pointer;margin-left:8px;">车辆下发</span>
                      <span v-else style="color:#999;border:1px solid #e0e0e0;font-size:12px;
                      display:inline-block;padding:0px 4px;border-radius:2px;cursor: pointer;margin-left:8px;">车辆已下发</span>
                    </span>
                </div>

                 <!-- 上传附件 -->
              <div v-if="item.type === 'file'">
                <upload-file
                  @getVal="getVal($event, item)"
                  :maxLength="9"
                  :only-read="false"
                  :value="ruleForm[item.value]"
                >
                </upload-file>
              </div>
             
                <!-- end -->
              </div>

              <!-- 新增状态 -->
              <div v-else>
                <el-input
                  v-if="item.type === 'input'"
                  v-model="ruleForm[item.value]"
                  :placeholder="item.placeholder"
                  size="small"
                  clearable
                  @blur="getBirthday(item.value)"
                />

                <el-input-number
                  v-if="item.type == 'num'"
                  v-model="ruleForm[item.value]"
                  :max="999999"
                  :min="1"
                  size="small"
                  controls-position="right"
                ></el-input-number>

                <!-- 时间选择 -->
                <el-date-picker
                  v-if="item.type === 'date'"
                  v-model="ruleForm[item.value]"
                  :placeholder="item.placeholder"
                  type="date"
                  size="small"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>

                <!-- 职位等级 -->
                <template v-if="item.slot === 'cascader'">
                  <div class="flx">
                    <el-cascader
                      v-model="ruleForm.position"
                      :options="treeData"
                      :placeholder="item.placeholder"
                      :props="propsPos"
                      filterable
                      size="small"
                    ></el-cascader>
                    <i class="el-icon-circle-plus" @click="addQuick"></i>
                  </div>
                </template>

                <!-- 部门 -->
                <select-department
                  v-if="item.slot === 'frame_id'"
                  :value="frames || []"
                  :is-site="true"
                  :placeholder="`选择所属部门`"
                  @changeMastart="changeMastart"
                  style="width: 100%"
                ></select-department>

                <!-- 负责人 -->
                <template v-if="item.type === 'radio'">
                  <el-radio v-model="ruleForm[item.value]" label="1">是</el-radio>
                  <el-radio v-model="ruleForm[item.value]" label="0">否</el-radio>
                </template>

                <!-- 直属上级 -->
                <div v-if="item.slot == 'superior_uid'">
                  <select-member
                    :only-one="true"
                    ref="selectMember"
                    :value="superiorUser || []"
                    @getSelectList="getSelectList"
                  >
                    <template v-slot:custom>
                      <span
                        class="pointer"
                        v-if="superiorUser.length == 0"
                        style="color: #1890ff"
                        @click="handlesuperiorOpen"
                        >添加</span
                      >
                      <span v-else @click="handlesuperiorOpen">
                        {{ superiorUser[0].name }}
                      </span>
                      <span
                        class="pointer ml10"
                        v-if="superiorUser.length > 0"
                        style="color: #1890ff"
                        @click="handlesuperiorOpen"
                        >修改</span
                      >
                    </template>
                  </select-member>
                </div>

                <div v-if="item.slot == 'manage_frame'">
                  <el-select
                    v-model="ruleForm.manage_frame"
                    placeholder="请选择"
                    size="small"
                    :disabled="ruleForm.is_admin != 1"
                    multiple
                    style="width: 100%"
                  >
                    <el-option v-for="item in frames" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                  </el-select>
                </div>

                <!-- select 下拉框 -->
                <el-select
                  v-if="item.type === 'select'"
                  v-model="ruleForm[item.value]"
                  :disabled="tabtypes !== 1 && item.value == 'type'"
                  :placeholder="item.placeholder"
                  size="small"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in item.optionsList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>

                <!-- dengshunbo 2024-12-21 -->
                <div v-if="componentStatus.type !='add'">
                    <el-switch  v-if="item.type === 'switchspan'"
                        v-model="switchValue" :width="swidthwidth"
                        active-color="#999999"
                        inactive-color="#1890ff"
                        active-text="未下发"
                        inactive-text="已下发"
                        :disabled="true"
                        >
                    </el-switch>
                    <div v-if="item.type === 'selectoption'">
                      <div>
                          <div style="display:inline-block;width:200px;"  class="menjiselectinput">
                            <el-select v-model="authend_group_sn" filterable multiple collapse-tags placeholder="搜索或选择门禁组(多选)" @change="goMenjinzuChange" size="small">
                              <el-option
                                v-for="item in menjinData"
                                :key="item.value"
                                :label="item.menjinzumingcheng"
                                :value="item.id">
                              </el-option>
                            </el-select>
                          </div>
                          <div style="width:160px;display:inline-block">
                            <el-date-picker style="width:100%;"
                                v-model="authend_time"  size="small"
                                type="date" 
                                placeholder="授权结束日期"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd" 
                                >
                            </el-date-picker>
                          </div>
                        
                      </div>
                    </div>
                    <span v-if="item.value === 'mj_member_sn'">{{ ruleForm.mj_member_sn }}</span>
                    <span v-if="item.value === 'mj_member_bh'">{{ ruleForm.mj_member_bh }}</span>
                    <div  v-if="item.type === 'carinput'">
                      <el-input
                        v-model="vehicle_number"
                        maxlength="8"
                        :placeholder="item.placeholder"
                        size="small"
                        clearable
                      />
                    </div>
                </div>
                <div v-if="item.type === 'selectoptions'" >
                  <!-- 被邀请权限组 -->
                  <el-select v-model="authend_group_primess" filterable multiple placeholder="搜索或选择权限组(多选)" @change="goMenjinzuChanges" size="small">
                    <el-option
                      v-for="item in menjinData"
                      :key="item.value"
                      :label="item.menjinzumingcheng"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
                <!-- end -->

                <!-- 上传图片 -->
                <upload-image
                  v-if="item.type === 'uploadImg'"
                  :append-to-body="true"
                  :imageUrl.sync="ruleForm[item.value]"
                  :isUploadStatus="componentStatus.type === 'edit' && FORMITEMISEDIT[itemIndex]"
                  :user="user"
                ></upload-image>

                <!-- 上传附件 -->
              <div v-if="item.type === 'file'">
                <upload-file
                  @getVal="getVal($event, item)"
                  :maxLength="9"
                  :only-read="false"
                  :value="ruleForm[item.value]"
                >
                </upload-file>
              </div>
             
              <!-- 上传附件 -->

                <!-- 系统设置 radio -->
                <template v-if="item.slot === 'radio'">
                  <el-radio
                    v-model="ruleForm.radio"
                    :disabled="componentStatus.type === 'edit' && FORMITEMISEDIT[itemIndex]"
                    label="1"
                    >直接加入</el-radio
                  >
                  <el-radio
                    v-model="ruleForm.radio"
                    :disabled="componentStatus.type === 'edit' && FORMITEMISEDIT[itemIndex]"
                    label="2"
                    >后续邀请</el-radio
                  >
                </template>
              </div>
            </el-form-item>
          </div>
          <!-- <div v-if="formItem.type !== 1" class="line"></div> -->
        </div>
      </div>
    </el-form>
    <!-- 新增时的工作经历 -->
    <Addwork ref="refwork" :add="add" :append-to-body="true" :edit="editTable" @addWorkFn="addWorkFn"></Addwork>
    <!-- 新增职位等级 -->
    <position-dialog ref="positionDialog" :config="positionConfig" @handleConfig="handleConfig"></position-dialog>
  </div>
</template>

<script>
import formOptions from '../mixins/index.js'
import myMixins from '../mixins/method.js'
// dengshunbo新增接口 menjinListCardApi， doorAuthCardApi
import {
  saveCard,
  jobsCreate,
  enterpriseCardIdApi,
  putCardApi,
  enterpriseWorkCreateApi,
  enterpriseEducationCreateApi,
  getWorkList,
  getEducationList,
  doorAuthCardApi,
  menjinListCardApi,
  doorOffCardApi,
  getUserPrimessApi,
  putUserinfoUpdateApi
} from '@/api/enterprise'
import {
  getResume,
  saveResume,
  userCreateWork,
  userCreateEducation,
  getUserWorkList,
  getUserEducationList,
  loginInfo
} from '@/api/user'
import { crudFangkeCarCreateApi, crudUserCarRegisterApi } from '@/api/develop.js'
export default {
  name: 'formOptions',
  mixins: [formOptions, myMixins],
  props: {
    componentStatus: {
      type: Object,
      default: () => {}
    },
    user: {
      type: String,
      default: () => ''
    },
    id: {
      type: [String, Number, Boolean],
      default: () => false
    },
    tabtypes: {
      type: [String, Number, Boolean],
      default: 1
    },
    photo: {
      type: String,
      default: () => ''
    }
  },

  data() {
    return {
      departmentShow: false,
      memberShow: false,
      userWorkId: '',
      add: 'work',
      choiceEdit: 0,
      isEdit: 0,
      edit: 'edit',
      editTable: '新增',
      superiorUser: [],
      frames: [],
      treeData: [],
      setIndex: 0,
      superiorFrame: [], // 上级部门
      propsPos: { value: 'id', label: 'name', multiple: false, checkStrictly: true },
      mastart_id: '', // 主部门,
      ruleForm: {
        name: '', // 员工姓名
        phone: '', // 手机号码
        photo: '',
        gong_hao:'', //工号 dengshunbo 2024-12-21
        mj_member_sn: '', // 人员SN(人员下发) dengshunbo 2024-12-21
        mj_group_sn:'', // // 人员SN(人员下发) dengshunbo 2024-12-21
        door_pwd:'', // dengshunbo 2024-12-21 通行密码
        door_card:'', // dengshunbo 2024-12-21 通行卡号
        access_control_team: '', // 门禁组 dengshunbo 2024-12-21
        yaoqingmenjinzu:'', // dengshunbo 2024-12-21 邀请门禁
        vehicle_number:'', // dengshunbo 2024-12-21 车牌号码
        laodonghetong: [],
        ruzhiziliao: [],
        lizhiziliao: [],
        qitaziliao: [],

        position: '', // 职位
        card_id: '', // 身份证号
        birthday: '', // 生日,
        age: '',
        sex: 0, // 性别: 0、未知；1、男；2、女；3、其他
        nation: '', // 民族
        education: '', // 学历
        acad: '', // 学位
        politic: '', // 政治面貌
        address: '', // 居住地
        native: '', // 籍贯
        marriage: '', // 婚姻状况:0、未婚；1、已婚；
        work_start: '', // 开始工作时间
        spare_name: '', // 紧急联系人
        spare_tel: '', // 紧急联系电话
        email: '', // 邮箱
        sort: 0, // 排序
        invite: '',
        quit_time: '', // 离职时间
        status: '', // 状态：1、正常；0、锁定；
        is_admin: '0', // 负责人1=主管,0=普通成员
        work_years: '', // 工作年限
        work_time: '', // 入职时间
        trial_time: '', // 试用时间
        formal_time: '', // 转正时间
        treaty_time: '', // 合同到期时间
        frame_id: [], // 部门
        frames: [],
        manage_frame: '',
        graduate_name: '', // 毕业院校
        graduate_date: '', // 毕业时间
        card_front: '', // 身份证正面
        card_both: '', // 身份证反面
        education_image: '', // 学历证书
        acad_image: '', // 学位证书
        social_num: '', // 社保账号
        fund_num: '', // 公积金账号
        bank_num: '', // 银行卡
        bank_name: '', // 开户行
        main_id: '', // 组织架构主部门ID
        edit_type: '',
        type: 1, // 员工状态
        interview_date: '', // 面试时间
        interview_position: '', // 面试职位
        superior_uid: '', // 直属上级
        superior: {},
        // 身份证照片测试
        radio: '1'
        // 测试字段
      },
      rangeUser: [],
      tabsIndex: 'personalFile',
      direction: 'rtl',
      activeName: 'first',
      positionData: [],
      positionLabel: [],
      workData: [],
      rangeUserText: [],
      positionText: '',
      manage_frameText: '',
      is_adminText: '',
      superiorText: '',
      is_partText: '',
      typeText: '',
      marriageText: '',
      sexText: '',
      educationText: '',
      frameText: [],
      personId: 1,
      positionConfig: {},

      // 工作经历表格头部
      workLabel: [
        {
          name: this.$t('toptable.startdate'),
          prop: 'start_time',
          width: '100'
        },
        {
          name: this.$t('toptable.endingdate'),
          prop: 'end_time',
          width: '100'
        },
        {
          name: this.$t('hr.company'),
          prop: 'company',
          width: '110'
        },
        {
          name: this.$t('hr.jobdescription'),
          prop: 'describe',
          width: '120'
        },
        {
          name: this.$t('toptable.post'),
          prop: 'position',
          width: '100'
        },
        {
          name: this.$t('hr.reasonsleaving'),
          prop: 'quit_reason',
          width: '120'
        }
      ],
      // 教育经历
      educationsData: [],
      loading: false,
      // 教育经历表格头部
      educationLabel: [
        {
          name: this.$t('hr.admissiontime'),
          prop: 'start_time',
          width: '100'
        },
        {
          name: this.$t('hr.graduationtime'),
          prop: 'end_time',
          width: '100'
        },
        {
          name: this.$t('hr.schoolname'),
          prop: 'school_name',
          width: '90'
        },
        {
          name: this.$t('hr.major'),
          prop: 'major',
          width: '90'
        },
        {
          name: this.$t('hr.education'),
          prop: 'education',
          width: '80'
        },
        {
          name: this.$t('hr.degree'),
          prop: 'academic',
          width: '80'
        },
        {
          name: this.$t('public.remarks'),
          prop: 'remark',
          width: '100'
        }
      ],
      // dengshun2024-12-20
      swidthwidth:70, 
      switchValue: true,
      isdoorAuth: 0,
      menjinData:[],
      authend_time: '',
      authend_group_sn:[],
      formMen: {
        member_sn:[],
        end_time:'',
        group_sn:[],
      },
      fromRulesMen: {
          group_sn: [
            { required: true, message: '请选择门禁组SN', trigger: 'change' }
          ],
          end_time: [
            { required: true, message: '请选择日期', trigger: 'change' }
          ],
      },
      menjiDialogVisible: false,
      authend_group_primess:[], // 能邀请的权限组
      user_id: '',
      userAdminData:{},
      userCreateData: {},
      formUserList: {
        account:'',
        avatar:'',
        job:'',
        
        name:'',
        phone:'',
        gong_hao:'',
        yaoqingmenjinzu:'',
        vehicle_number:'',
        mj_member_sn:'',
        mj_member_bh:'',
        door_card:'',
        door_pwd:'',
        sushe_hao: '',
        //is_user_authorize:'', // 人员创建下发
        // is_mj_authorize:'',  // 门禁授权
        //access_control_team:'', // 已下发门禁组

      },
      access_control_team_old:'', // 用户已有的门禁组id-数组字符串
      is_mj_authorize_old:'', // // 门禁授权1已授权
      is_user_authorize_old:'', // 人员创建下发1已下发

      vehicle_number:'',
      formitemLoading: false,
      fileArrayuser: []
      // end
    }
  },

  mounted() {
    this.getTreeData()
    // dengshun2024-12-20
    this.menjinCardAuth();
    const now = new Date();
    const year = now.getFullYear();
    const month = now.getMonth() + 1 > 9 ? now.getMonth() + 1 : '0' + (now.getMonth() + 1); // 月份从0开始，需要加1
    const day = now.getDate() > 9 ? now.getDate() : '0' + now.getDate();
    this.authend_time = year + 10 + '-' + month + '-' + day;
    // end
  },
  computed: {
    
    newFrom() {
      // 数据在minxins
      if (this.user == '个人简历') {
        return this.userForm
      } else if (this.tabtypes === 0) {
        return this.notEntry
      } else if (this.tabtypes === 2) {
        this.FORMOPTIONS.forEach((item) => {
          if (item.title == '职工信息') {
            let obj = {
              type: 'date',
              label: '离职时间：',
              value: 'quit_time',
              placeholder: '请选择离职时间'
            }

            item.data.push(obj)
          }
        })
        return this.FORMOPTIONS
      } else {
        this.FORMOPTIONS.forEach((item) => {
          if (item.title == '职工信息') {
            if (item.data.length == 7) {
              item.data.splice(item.data.length - 1, 1)
            }

            item.data[1].optionsList.splice(2, 2)
          }
        })
        return this.FORMOPTIONS
      }
    }
  },
  methods: {
    // deng2024-12-20 车辆下发事件
    goCarxiafa(){
      let uid = this.ruleForm.uid || ''
      crudUserCarRegisterApi({uid: uid}).then(res=>{
       
      }).catch(err=>{
          if(err.data.code==200){
            this.$message.success("车辆下发成功")
          }else{
            this.$message.error(err.data.message)
          }
      })
      
    },
    // 上传附件事件
    getVal(val, item) {
      this.fileArrayuser = val;
      let arr = []
      val.map((el) => {
        arr.push(el.url)
      })
      this.ruleForm[item.value] = val || []; // arr.length > 0 ? arr.join(",") : '';
    },
    //门禁授权获取门禁组
    getDoorAuth(){
      this.menjiDialogVisible = true;
      this.menjinCardAuth();
    },
    // 门禁授权
    doorCardAuth(index=1, itemindex=100) {
      let groupsn = this.formMen.group_sn.length > 0? this.formMen.group_sn.join(",") : '';
      if(this.is_user_authorize_old != 1){ // 是否人员创建下发
        this.$message.error("请先下发人员后再授权")
        return;
      }
      let formData  = {member_sn: this.ruleForm.mj_member_sn, group_arr: groupsn, end_time: this.authend_time+' 23:59:59'}
      doorAuthCardApi(formData)
        .then((res) => {
          if(res.data.code==200){
             this.$message.success(res.data.msg)
             if(index==2){
                this.formitemLoading = false;
                this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemindex); // 实体用户数据更新
             }else{
                this.formitemLoading = false;
             }
          }else{
            this.$message.success(err.data.message || '授权失败')
            this.formitemLoading = false;
          }
        })
        .catch((err) => {
          if(err.data.code == 200){
              this.$message.success(err.data.message)
              if(index==2){
                this.formitemLoading = false;
                this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemindex); // 实体用户数据更新
              }
          }else{
              this.formitemLoading = false;
              this.$message.success(err.data.message || '授权失败')
          }
        })
    },
    // 取消门禁授权 -清空所属门禁组
    doorCancelCardAuth(index=1, itemindex=100) {
      let formData  = {member_sn: this.ruleForm.mj_member_sn}
      doorOffCardApi(formData).then((res) => {
            if(res.data.code == 200){
                if(index==3){ // 取消门禁授权后重新调用授权
                  this.doorCardAuth(2, itemindex)
                }else{
                  this.$message.success('取消授权成功');
                  this.authend_group_sn = [] // 清空数据
                  this.formMen.group_sn = [] 
                  this.ruleForm.access_control_team = '' // 清空数据
                  if(index==2){ // 取消成功更新用户门禁数据
                    this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemindex);
                  }else{
                    this.formitemLoading = false;
                  }
                }
            }else{
                this.formitemLoading = false;
                this.$message.error(res.message || '取消授权失败')

            }
          }).catch((err) => {
              if(err.data.code == 200){
                if(index==3){
                    this.doorCardAuth(2, itemindex)
                  }else{
                    this.$message.success('取消授权成功')
                    this.formMen.group_sn = []
                    this.authend_group_sn = [] // 清空数据
                    this.ruleForm.access_control_team = '' // 清空数据
                    if(index==2){ // 取消成功更新用户门禁数据
                      this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemindex);
                    }else{
                      this.formitemLoading = false;
                    }
                  }
              }else{
                  this.$message.error(err.message || '取消授权失败')
                  this.formitemLoading = false;
              }
              
        })
      
    },
    mergeAndDistinct(array1, array2) {
        let arrayteam = array1.concat(array2)
        // 创建一个新数组，用于存储不重复的元素
        let uniqueArr = [];
        // 遍历合并后的数组
        arrayteam.forEach(item => {
          // 如果新数组中没有当前元素，则添加
          if (!uniqueArr.includes(item)) {
            uniqueArr.push(item);
          } else {
            // 如果有重复元素，则从新数组中删除
            let index = uniqueArr.indexOf(item);
            if (index !== -1) {
              uniqueArr.splice(index, 1);
            }
          }
        });
        return uniqueArr;
    },
    // 门禁组
    menjinCardAuth() {
      let dataform = {page:1, limit: 100,scope_frame:'all', show_search_type:'0', is_system:1, view_search_boolean:'', view_search:[],order_by:[]}
      menjinListCardApi(dataform)
        .then((res) => {
           if(res.status==200){
              this.menjinData = res.data.list;
           }
        })
        .catch((err) => {})
        .finally(() => {
       
        })
        this.isdoorAuth = 1;
    },
    // 选择门禁组
    goMenjinzuChange(e){
      if(e && e.length > 0){
        this.formMen.group_sn = e
        this.ruleForm.access_control_team = e.join(",")
      }else{
         this.ruleForm.access_control_team = ''
      }
    },
    // 获取用户信息数据
    getUserPrimess(id) {
      getUserPrimessApi(id)
        .then((res) => {
           if(res.status==200){
              let resdata = res.data;
              this.userAdminData = resdata;
              let resdatainfo = resdata.module_info;
              this.formUserList.account = resdatainfo.account;
              this.formUserList.avatar = resdatainfo.avatar;
              this.formUserList.id = id;
              this.formUserList.job = resdatainfo.job;
              this.formUserList.name = resdatainfo.name;
              this.formUserList.phone = resdatainfo.phone;
              this.formUserList.yaoqingmenjinzu = resdatainfo.yaoqingmenjinzu || '';
              this.formUserList.vehicle_number = resdatainfo.vehicle_number || '';
              this.vehicle_number = resdatainfo.vehicle_number || '';

              this.formUserList.mj_member_sn = resdatainfo.mj_member_sn || '';
              this.formUserList.mj_member_bh = resdatainfo.mj_member_bh || '';
              this.formUserList.door_card = resdatainfo.door_card || '';
              this.formUserList.door_pwd = resdatainfo.door_pwd || '';
              this.formUserList.gong_hao = resdatainfo.gong_hao || '';
              this.formUserList.sushe_hao = resdatainfo.sushe_hao || '';
              this.access_control_team_old = resdatainfo.access_control_team || '';
              this.is_mj_authorize_old = resdatainfo.is_mj_authorize;
              this.is_user_authorize_old = resdatainfo.is_user_authorize;
              if(resdatainfo.yaoqingmenjinzu){ // 邀请门禁组
                let yqzu = resdatainfo.yaoqingmenjinzu;
                this.authend_group_primess = yqzu.split(",").map(Number)
              }else{
                this.authend_group_primess = ''
              }
               // dengshunbo 2024-12-20
              this.ruleForm.gong_hao = resdatainfo.gong_hao || '';
              this.ruleForm.mj_member_sn = resdatainfo.mj_member_sn || '';
              this.ruleForm.mj_member_bh = resdatainfo.mj_member_bh || '';
              this.ruleForm.door_card = resdatainfo.door_card || '';
              this.ruleForm.door_pwd = resdatainfo.door_pwd || '';
              this.ruleForm.access_control_team = resdatainfo.access_control_team || '';
              if(resdatainfo.access_control_team){ // 所属门禁组
                let accesscontrolteam = resdatainfo.access_control_team.split(",");
                this.formMen.group_sn = accesscontrolteam;
                this.authend_group_sn = accesscontrolteam.map(Number);
              }else{
                this.authend_group_sn = [];
                this.formMen.group_sn = [];
              }

              if(resdatainfo.is_user_authorize==1){ // 人员创建已下发
                  this.switchValue = false;
              }else{
                  this.switchValue = true;
              }
              
              // end

             
           }
        })
        .catch((err) => {})
        .finally(() => {
       
        })
    },
   
    // 邀请的权限组
    goMenjinzuChanges(e){
      if(e && e.length > 0){
        this.formUserList.yaoqingmenjinzu = e.join(",")
      }else{
         this.formUserList.yaoqingmenjinzu = ''
      }
    },
    getFileterData(val){
       let vname = []
       if(val && val.length > 0){
           let valarr = val.map(Number);
           for(let i=0;i< this.menjinData.length;i++){
              if(valarr.includes(this.menjinData[i].id)){
                vname.push(this.menjinData[i].menjinzumingcheng);
              }
           }   
           return vname.join(",");
       }else{
          return ''
       }
    },
    // 用户信息更新调用更新缓存
    async getInfo() {
      const res = await loginInfo()
      this.$store.commit('user/SET_USERINFO', res.data.userInfo)
      this.$store.commit('user/SET_ENTINFO', res.data.enterprise)
    },
    // end
    // 保存个人简历信息
    saveResume(val) {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.ruleForm.works = this.workData
          this.ruleForm.photo = val
          this.ruleForm.frames = this.rangeUser
          this.ruleForm.frame_id = this.frames
          saveResume(this.ruleForm)
            .then((res) => {
              this.$emit('hiddenSave')
            })
            .catch((err) => {
              this.$emit('hiddenSave')
            })
        }
      })
    },

    // 身份证获取出生日期
    getBirthday(val) {
      if (val !== 'card_id') return
      const cardId = this.ruleForm.card_id
      if (!cardId || (cardId.length !== 15 && cardId.length !== 18)) {
        this.ruleForm.birthday = ''
        this.ruleForm.sex = 0
        this.ruleForm.age = ''
        return
      }

      let birthday = ''
      let sex = ''

      if (cardId.length === 15) {
        birthday = '19' + cardId.substr(6, 6)
        sex = cardId.substring(14, 15)
      } else if (cardId.length === 18) {
        birthday = cardId.substr(6, 8)
        sex = cardId.substring(16, 17)
      }

      birthday = birthday.replace(/(.{4})(.{2})/, '$1-$2-')
      this.ruleForm.birthday = birthday

      const birthDate = new Date(birthday)
      const currentDate = new Date()
      const age =
        currentDate.getFullYear() -
        birthDate.getFullYear() -
        (currentDate.getMonth() < birthDate.getMonth() ||
        (currentDate.getMonth() === birthDate.getMonth() && currentDate.getDate() < birthDate.getDate())
          ? 1
          : 0)

      this.ruleForm.sex = sex % 2 === 0 ? 2 : 1
      this.ruleForm.age = isNaN(age) ? '' : age
    },

    restFn(data) {
      this.$refs.form.resetFields()
      this.FORMITEMISEDIT[data] = !this.FORMITEMISEDIT[data]
      this.enterpriseCardId()
    },
    // 默认值
    defaultFn() {
      this.getDate()
      if (this.tabtypes == 0) {
        this.$set(this.ruleForm, 'type', '未入职')
      } else if (this.tabtypes == 1) {
        this.$set(this.ruleForm, 'type', 2)
      } else if (this.tabtypes == 2) {
        this.$set(this.ruleForm, 'type', 4)
        this.typeText = '离职'
      }
    },

    // 获取个人简历信息
    getResume() {
      getResume().then((res) => {
        this.workData = res.data.works
        this.educationsData = res.data.educations
        res.data.education = Number(res.data.education)
        this.ruleForm = res.data
        if (this.ruleForm.education == 0) {
          this.ruleForm.education = ''
        }
        this.userWorkId = res.data.id
        if (this.ruleForm.card_id) {
          this.getBirthday()
        }
        this.$emit('getPhoto', res.data.photo)
      })
    },

    // 新增:保存个人档案信息
    saveCard() {
      this.ruleForm.works = this.workData
      this.ruleForm.educations = this.educationsData
      this.ruleForm.photo = this.photo
      let position = ''
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.ruleForm.position.length > 0) {
            position = this.ruleForm.position[0]
          }
          saveCard(this.tabtypes, {
            ...this.ruleForm,
            position
          }).then((res) => {
            if (res.status == 200) {
              this.$emit('submitOk')
              this.resetForm()
              this.$store.dispatch('user/getMember')
            }
          })
        }
      })
    },

    // 编辑: 保存个人档案信息
    formItemEdit(type, itemIndex) {
      let valiSome = ['interview_position', 'interview_date', 'is_part', 'type']
      let basicSome = ['name', 'phone', 'position', 'frame_id']
      let flag = true
      if (type == 'staff') {
        valiSome.forEach((item) => {
          this.$refs.form.validateField(item, (valid) => {
            if (valid.length) {
              return (flag = false)
            }
          })
        })
        if (flag) {
          this.editFn(type, itemIndex)
        }
      } else if (type == 'basic') {
        basicSome.forEach((item) => {
          this.$refs.form.validateField(item, (valid) => {
            if (valid.length) {
              return (flag = false)
            }
          })
        })
        if (flag) {
          this.editFn(type, itemIndex)
        }
      } else if (type == 'user') {
        this.$refs.form.validateField('card_id', (valid) => {
          if (!valid) {
            this.editFn(type, itemIndex)
          }
        })
      } else if(type== 'allUser'){ // dengshunbo 2024-12-20
        this.formUserList.sushe_hao = this.ruleForm.sushe_hao || '';
        this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemIndex);
      } else if(type == 'all'){  // 门禁信息修改 dengshunbo 2024-12-20
        this.formitemLoading = true;
        this.formUserList.mj_member_sn = this.ruleForm.mj_member_sn || '';
        this.formUserList.mj_member_bh = this.ruleForm.mj_member_bh || '';
        this.formUserList.door_card = this.ruleForm.door_card || '';
        this.formUserList.door_pwd = this.ruleForm.door_pwd || '';
        this.ruleForm.vehicle_number = this.vehicle_number;
        this.formUserList.vehicle_number = this.vehicle_number;
        this.formUserList.gong_hao = this.ruleForm.gong_hao || '';
        if(this.is_user_authorize_old ==1){ // 人员已下发1
          if(this.access_control_team_old !=''){ // 已授权门禁组
            if(this.ruleForm.access_control_team==''){
                //  this.formUserList.is_mj_authorize = 0;
                //  this.formUserList.access_control_team = '';
                //  this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemIndex);

                this.doorCancelCardAuth(2, itemIndex) // 先调用清除授权，清除授权后index=2更新用户信息
            }else{
              let array1 = (this.access_control_team_old.split(",")).map(Number); // 已授权门禁组数组
              let array2 = (this.ruleForm.access_control_team.split(",")).map(Number); // 当前选择门禁组
              const areEqual = array1.length === array2.length && array1.every((value, index) => value === array2[index]);
              if(areEqual){ // 判断授权门禁组没有变化-直接调用数据更新
                  this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, 1); // 实体用户数据更新
              }else{ // 授权门禁组有变化
                this.doorCancelCardAuth(3, itemIndex) // 先调用清除授权，清除授权后再重新下发授权index=3重新调用授权
              }
            }
          }else{ // 未授权门禁组-当前选择门禁组为空
              if(this.ruleForm.access_control_team==''){ // 判断是否选择门禁组-当前未选择门禁组
                // 直接调用实体用户数据更新，不调用授权门禁组操作
                // this.formUserList.mj_member_bh = ''
                // this.formUserList.mj_member_sn = ''
                // this.formUserList.is_user_authorize = 0;
                //this.doorCancelCardAuth(2, itemIndex) // 先调用清除授权，清除授权后index=2更新用户信息
                this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemIndex);
              }else{ // 已选择门禁组-调用门禁组操作
                this.doorCardAuth(2, itemIndex); // 调用门禁授权index=2 并更新用户数据
              }
          }
        }else{ // 人员未下发0或空
          if(this.ruleForm.access_control_team==''){ // 未选择门禁组-直接修改实体用户
            // 测试数据
            //this.formUserList.mj_member_bh = ''
            //this.formUserList.mj_member_sn = ''

            // this.formUserList.mj_member_bh = 5001;
            // this.formUserList.mj_member_sn = 7303304173183827969;
            // end
            this.getUserUpdate(this.ruleForm.id, this.formUserList, 1, itemIndex);
          }else{
            this.$message.error("请先操作人员创建下发然后在选择授权门禁组")
            return;
          }
        }
        
     
      } else {
        this.editFn(type, itemIndex)
      }
    },
    async editFn(type, itemIndex) {
      this.FORMITEMISEDIT[itemIndex] = !this.FORMITEMISEDIT[itemIndex]
      this.ruleForm.edit_type = type
      if (this.ruleForm.position.length > 0) {
        this.ruleForm.position = this.ruleForm.position[this.ruleForm.position.length - 1]
      }
      this.ruleForm.frames = []
      this.ruleForm.photo = this.photo
      this.rangeUser.forEach((item) => {
        this.ruleForm.frames.push(item.id)
      })
      // 原代码
      // await putCardApi(this.id, this.ruleForm)
      // await this.enterpriseCardId()
      // await this.$store.dispatch('user/getMember')
      // end
      // dengshunbo 2024-12-20
      await putCardApi(this.id, this.ruleForm)
      if(type=='basic'){ // 修改基本信息时，需要修改门实体用户的工号
          if(this.formUserList.gong_hao != this.ruleForm.gong_hao){ // 判断工号有改动是调用
            this.formUserList.gong_hao = this.ruleForm.gong_hao;
            await this.getUserUpdate(this.ruleForm.id, this.formUserList, 2, itemIndex);
          }else{
            await this.enterpriseCardId() 
          }
      }else if(type== 'card'){
        let formdata = {
          laodonghetong: this.ruleForm.laodonghetong,
          ruzhiziliao:  this.ruleForm.ruzhiziliao,
          lizhiziliao:  this.ruleForm.lizhiziliao,
          qitaziliao:  this.ruleForm.qitaziliao,
        }
        this.getUserUpdate(this.ruleForm.id, formdata, 2, itemIndex);
        await this.enterpriseCardId() 
        await this.$store.dispatch('user/getMember')
      }else{
         await this.enterpriseCardId() 
         await this.$store.dispatch('user/getMember')
      }
      // end
    },
    // dengshunbo 2024-12-20
    // 修改用户实体内的字段数据
    getUserUpdate(id, formUserData, index=1, editindex=100){
      let formobj = JSON.stringify(formUserData)
      let datas = {
        id: id,
        data: formobj
      }
      putUserinfoUpdateApi(datas).then((res) => {
          this.formitemLoading = false;
          // this.enterpriseCardId()
             if(res.data.code==200){
                if(editindex !=100){
                  this.restFn(editindex)
                 
                  // this.getInfo();
                }
            }
      }).catch((err)=>{
            this.formitemLoading = false;
            // this.enterpriseCardId()
            if(err.data.code==200){
                if(editindex !=100){
                  this.restFn(editindex)
                  //this.getInfo();
                }
            }
      })
    },

    // 新增：职位等级
    addQuick() {
      this.positionConfig = {
        title: '添加职位',
        width: '520px',
        data: this.treeData
      }
      this.$refs.positionDialog.handleOpen()
    },

    handleConfig() {
      this.getTreeData()
    },

    // 新增: 获取工作/教育经历列表
    addWorkFn(data, val) {
      if (val == 'work') {
        if (this.editTable == '编辑') {
          this.workData.splice(this.setIndex, 1, data)
        } else {
          this.workData.push(data)
        }
      } else {
        if (this.editTable == '编辑') {
          this.educationsData.splice(this.setIndex, 1, data)
        } else {
          this.educationsData.push(data)
        }
      }
    },

    // 刷新个人简历工作经历列表
    async getUserWorkList() {
      let data = {
        resume_id: this.userWorkId
      }
      const result = await getUserWorkList(data)
      this.workData = result.data.list
    },

    // 刷新个人简历教育经历列表
    async getUserEducationList() {
      const result = await getUserEducationList()
      this.educationsData = result.data.list
    },

    // 新增: 编辑工作/教育经历
    putWork(row, index, type) {
      this.setIndex = index
      this.editTable = '编辑'
      if (type === 'works') {
        this.$refs.refwork.title = '编辑工作经历'
        this.add = 'work'
        this.$nextTick(() => {
          this.$refs.refwork.workForm = row
        })
      } else {
        this.$refs.refwork.title = '编辑教育经历'
        this.add = 'education'
        this.$nextTick(() => {
          this.$refs.refwork.educationForm = row
        })
      }

      this.$refs.refwork.dialogFormVisible = true
    },

    // 新增：删除工作/教育经历
    deleteWork(row, index, type) {
      if (type === 'works') {
        this.workData.splice(index, 1)
      }
      if (type === 'education') {
        this.educationsData.splice(index, 1)
      }
    },

    // 编辑: 获取工作经历列表
    async getWorkList() {
      let data = {
        user_id: this.id
      }
      const result = await getWorkList(data)
      this.workData = result.data.list
    },

    //  编辑: 新增工作经历
    addWorks(val) {
      if (val === '工作经历') {
        if (this.user === '个人简历') {
          this.$modalForm(userCreateWork({})).then((res) => {
            this.getUserWorkList()
          })
        } else {
          this.add = 'work'
          this.editTable = '新增'
          this.$refs.refwork.title = '新增工作经历'
          this.$refs.refwork.workForm = {}
          this.$refs.refwork.dialogFormVisible = true
        }
      }
      if (val === '教育经历') {
        if (this.user === '个人简历') {
          this.$modalForm(userCreateEducation({})).then((res) => {
            this.getUserEducationList()
          })
        } else {
          this.add = 'education'
          this.$refs.refwork.educationForm = {}
          this.editTable = '新增'
          this.$refs.refwork.title = '新增教育经历'
          this.$refs.refwork.dialogFormVisible = true
        }
      }
    },

    // 编辑: 编辑工作经历
    editWorks() {
      this.$modalForm(
        enterpriseWorkCreateApi({
          user_id: this.id
        })
      ).then((res) => {
        this.getWorkList()
      })
    },

    // 编辑: 获取教育经历列表
    async getEducationList() {
      let data = {
        user_id: this.id
      }
      const result = await getEducationList(data)
      this.educationsData = result.data.list
    },

    // 编辑 新增教育经历
    editEducation() {
      this.$modalForm(
        enterpriseEducationCreateApi({
          user_id: this.id
        })
      ).then((res) => {
        this.getEducationList()
      })
    },

    // 获取职位tree数据
    async getTreeData() {
      const result = await jobsCreate()
      this.treeData = result.data.tree
    },

    // 选择部门回调
    changeMastart(data) {
      this.frames = data
      let frameIdArr = []
      this.frames.forEach((item) => {
        frameIdArr.push(item.id)
        this.ruleForm.frame_id = frameIdArr
      })
      const preMastartId = this.mastart_id
      this.frames.forEach((el) => {
        if (el.is_mastart) {
          this.ruleForm.main_id = el.id
          if (preMastartId) {
            this.superiorFrame = this.superiorFrame.map((i) => {
              return i.id === preMastartId ? el : i
            })
          } else {
            this.superiorFrame.push(el)
          }
        }
      })
    },

    // 添加负责人
    handlesuperiorOpen() {
      setTimeout(() => {
        this.$refs.selectMember[0].handlePopoverShow()
      }, 200)
    },
    // 选择人员回调
    getSelectList(data) {
      this.superiorUser = data
      this.ruleForm.superior = this.superiorUser[0]
      this.ruleForm.superior_uid = this.superiorUser[0].value
    },

    // 删除管理范围
    cardTag(index, val) {
      this.rangeUser = this.rangeUser.filter((item) => {
        return item.id != val.id
      })
    },

    // 删除所在部门
    handleDeleteDep(index) {
      this.$refs[`popover-${index}`][0].doClose()
      this.frames.splice(index, 1)
    },

    // 回显数据
    async enterpriseCardId() {
      this.superiorUser = []
      this.rangeUser = []
      const res = await enterpriseCardIdApi(this.id)
      this.formatData(res)
      this.ruleForm = res.data
      if(res.data.laodonghetong){
        this.ruleForm.laodonghetong = JSON.parse(res.data.laodonghetong)
      }else{
        this.ruleForm.laodonghetong = []
      }
      if(res.data.ruzhiziliao){
        this.ruleForm.ruzhiziliao = JSON.parse(res.data.ruzhiziliao)
      }else{
        this.ruleForm.ruzhiziliao = []
      }
      if(res.data.lizhiziliao ){
        this.ruleForm.lizhiziliao  = JSON.parse(res.data.lizhiziliao)
      }else{
        this.ruleForm.lizhiziliao  = []
      }

      if(res.data.qitaziliao){
        this.ruleForm.qitaziliao = JSON.parse(res.data.qitaziliao)
      }else{
        this.ruleForm.qitaziliao = []
      }
      if (!this.ruleForm.age) {
        this.ruleForm.age = ''
      }
      if (!this.ruleForm.work_years) {
        this.ruleForm.work_years = ''
      }
      if (!this.tabtypes) {
        this.typeText = '未入职'
        this.ruleForm.type = 3
      }
      let newFrame = []
      let newId = []
      this.positionText = []
      this.manage_frameText = ''
      this.frameText = []
      this.workData = res.data.works
      this.educationsData = res.data.educations
      this.ruleForm.frame_id = []
      res.data.frames.map((item) => {
        this.ruleForm.frame_id.push(item.id)
      })
      this.rangeUserText = []
      let typeNew = ''
      if (!this.tabtypes) {
        typeNew = '未入职'
      } else if (this.tabtypes === 1) {
        typeNew = '在职'
      } else {
        typeNew = '离职'
      }
      let userInfo = {
        name: res.data.name,
        id: res.data.id,
        type: typeNew,
        uid: res.data.uid,
        position: res.data.job ? res.data.job.name : '暂无职位',
        gong_hao: res.data.gong_hao, // dengshunbo 2024-12-20 新增
      }
      this.$emit('userInfoFn', userInfo)
      this.$emit('getPhoto', res.data.photo)
      this.frames = res.data.frames
      this.frames.forEach((el) => {
        if (el.is_mastart) {
          this.ruleForm.main_id = el.id
          this.mastart_id = el.id
        }
        let val = {
          name: el.name,
          is_mastart: el.is_mastart
        }
        newFrame.push(val)
        newId.push(el.id)
        this.frameText = newFrame
      })
      this.rangeUser = res.data.scope
      this.rangeUser.forEach((item, index) => {
        this.rangeUserText.push(item.name)
      })
      res.data.education = Number(res.data.education)

      this.ruleForm.position = res.data.job ? res.data.job.id : ''
      this.positionText = res.data.job ? res.data.job.name : ''
      if (res.data.manage_frames.length > 0) {
        let arr = []
        res.data.manage_frames.map((item) => {
          arr.push(item.name)
        })
        this.manage_frameText = arr.join(',')
      } else {
        this.manage_frameText = '--'
      }

      this.is_adminText = res.data.is_admin === 1 ? '是' : '否'
      this.ruleForm.is_admin = res.data.is_admin + ''
      this.superiorText = res.data.superior ? res.data.superior.name : ''
      if (res.data.superior.length !== 0) {
        this.superiorUser.push(res.data.superior)
        this.ruleForm.superior_uid = this.superiorUser[0].id
      } else {
        this.ruleForm.superior_uid = ''
      }
      // dengshunbo 2024-12-20
      // if(this.vehicle_number){
      //   this.ruleForm.vehicle_number = this.vehicle_number;
      // }
      this.getUserPrimess(this.ruleForm.id);
      // end
    }
  },

  components: {
    // 新增: 添加工作/教育经历
    Addwork: () => import('./addWork'),
    // 编辑: 工作/教育经历
    tableBox: () => import('../components/tableBox'),
    // 上传图片
    UploadImage: () => import('../src/UploadImage.vue'),
    ElImageViewer: () => import('element-ui/packages/image/src/image-viewer'),

    selectMember: () => import('@/components/form-common/select-member'),
    selectDepartment: () => import('@/components/form-common/select-department'),

    // 职位等级
    positionDialog: () => import('@/views/hr/archives/components/positionDialog'),
    // 附件上传
    uploadFile: () => import('@/components/form-common/oa-upload'),
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-drawer__body {
  overflow-y: hidden;
}
.upload-file {
  display: inline-block;
}
.line {
  width: 100%;
  height: 3px;
  margin-top: 10px;
  margin-bottom: 30px;
  border-bottom: 1px dashed #ebeef5;
}
// .m10 {
//   margin: 10px 0 30px 0 !important;
// }

.label {
  color: #909399;
  font-weight: 400;
  font-size: 13px;
  font-family: PingFangSC-Regular, PingFang SC;
}
.activeItem {
  margin: -7px -10px !important;
}
.item-superior {
  margin-left: -88px;

  span {
    cursor: pointer;
    font-size: 13px;
  }
}
/deep/ .el-form-item__label,
.el-form-item__content {
  // font-size: 12px !important;
  // font-weight: 400;
  // color: #303133;
}
.text-title {
  font-size: 12px !important;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #909399;
  .format {
    font-size: 10px;
  }
}
.label-item {
  font-size: 13px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #303133;
}
/deep/ .el-cascader {
  width: 100%;
}
/deep/ .el-input--small {
  font-size: 13px;
}
/deep/ .el-input--medium {
  font-size: 13px;
}
/deep/ .el-button--small {
  width: 44px;
  height: 28px;
  padding: 0;
  font-size: 13px;
}
.labelfont {
  font-size: 13px;
  font-weight: 400;
  color: #303133;
}
.el-icon-warning {
  font-size: 10px;
  color: #1890ff;
  opacity: 0.5;
}
/deep/ .form-box .form-item .el-input {
  width: 100% !important;
}
/deep/ .el-drawer__close-btn {
  margin-bottom: 0;
}
.m10 {
  margin: 5px 0 20px 10px;
  color: #666;
}
.add {
  color: #1890ff;
  margin-left: 20px;
  cursor: pointer;
}
.main {
  margin: 20px;
  overflow-y: hidden;
}
/deep/ .el-tabs__item {
  font-weight: 700;
  z-index: 9999;
}
/deep/ .el-form-item__label {
  padding-right: 4px !important;
}
.table-box {
  height: 600px;
  overflow-y: auto;
  padding: 0 13px;
  .table-item {
    padding-bottom: 29px;
    .title {
      margin: 20px 0 14px;
      padding-left: 10px;
      border-left: 2px solid #1890ff;
      font-size: 13px;
    }
  }
}
.flx {
  display: flex;
}

.el-icon-circle-plus {
  margin-top: 8px;
  margin-left: 10px;
  font-size: 14px;
  color: #ccc;
}
.form-item-section {
  width: 100%;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  padding: 0px 15px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;

  span {
    margin: 5px 5px 5px 5px;
    &:last-of-type {
      margin-right: 0;
    }
  }
}
.header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}
.add-text {
  font-size: 14px;
  font-weight: 500;
  color: #1890ff;
  margin: 20px 20px 0 0;
}

.drawer-body {
  display: flex;
}

.right-item {
  line-height: 25px;
  cursor: pointer;
  margin-top: 10px;

  &:first-child {
    margin-top: 0;
  }
}

.right {
  margin: 0 20px;
  width: calc(100% - 180px);
  height: 700px;
  overflow-y: auto;
  padding-bottom: 80px;
  padding-top: 20px;
}

.right::-webkit-scrollbar {
  height: 0;
  width: 0;
}

.from-item-title {
  display: flex;
  justify-content: space-between;
  height: 14px;
  line-height: 14px;
  margin-bottom: 10px;
  align-items: center;
  margin-top: 10px;
  border-left: 2px solid #1890ff;
  .title {
    display: inline-block;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
  }

  span {
    padding-left: 10px;
    font-weight: 500;
    font-size: 13px;
  }
}

.form-box {
  display: flex;
  flex-wrap: wrap;
  // margin: 0 20px;
  justify-content: space-between;

  .form-item {
    width: 48%;

    /deep/ .el-form-item__content {
      width: calc(100% - 90px);
    }

    /deep/ .el-input {
      width: 95%;
    }

    /deep/ .el-select {
      width: 100%;
    }

    /deep/ .el-form-item {
      margin-bottom: 20px;
    }

    /deep/ .el-textarea__inner {
      resize: none;
    }
    /deep/ label{
       line-height:20px;padding:8px 0;
    }
    /deep/ .label-item{
       line-height: 20px;padding:8px 0;
    }
  }
}

.plan-footer-one {
  height: 36px;
  line-height: 36px;

  .placeholder {
    font-size: 14px;
    color: #ccc;
  }

  span {
    margin-right: 6px;
  }
}

.from-text {
  margin: 20px 0;
  font-size: 11px;
  color: gray;
}

/deep/ .avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

/deep/ .avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  text-align: center;
}

/deep/ .el-upload--picture-card {
  width: 160px;
  height: 100px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  line-height: 100px;
  position: relative;
  overflow: hidden;
}

/deep/ .avatar {
  width: 160px;
  height: 100px;
  display: block;
}
.tabsEdit {
  height: 56px;
  display: flex;
  justify-content: space-between;
  .invitationUrl {
    margin-top: 10px;
    margin-right: 20px;
  }
}

.placeholder-text {
  font-size: 13px;
  color: #ccc;
  line-height: 20px;
}
</style>
